package com.dzt.androidframework.view;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.dzt.androidframework.R;
import com.dzt.androidframework.activity.ActivityTitle;
import com.lljjcoder.style.citylist.CityListSelectActivity;
import com.lljjcoder.style.citylist.bean.CityInfoBean;

import org.xutils.view.annotation.ViewInject;

public class CityPickerListActivity extends ActivityTitle {
	@ViewInject(R.id.list_tv)
	TextView mListTv;
	@ViewInject(R.id.result_tv)
	TextView mResultTv;

	@Override
	protected void initData(Bundle savedInstanceState) {

	}

	@Override
	protected String[] initPermissions() {
		return new String[0];
	}

	@Override
	protected int getLayoutId() {
		return R.layout.activity_city_picker_list;
	}

	@Override
	protected void initParams() {
		setTitleView("城市选择器");
		mListTv.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				list();
			}
		});
	}

	public void list() {
		Intent intent = new Intent(CityPickerListActivity.this, CityListSelectActivity.class);
		startActivityForResult(intent, CityListSelectActivity.CITY_SELECT_RESULT_FRAG);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == CityListSelectActivity.CITY_SELECT_RESULT_FRAG) {
			if (resultCode == RESULT_OK) {
				if (data == null) {
					return;
				}
				Bundle bundle = data.getExtras();

				CityInfoBean cityInfoBean = (CityInfoBean) bundle.getParcelable("cityinfo");

				if (null == cityInfoBean) {
					return;
				}

				mResultTv.setText("城市： " + cityInfoBean.toString());
			}
		}
	}
}
